import api from '@/service/config/api.js'
export default {
	data() {
		return {
			current: 1,
			size: 15,
			total: 1,
			end: false,
			loading: true,
			httpMethod: 'get',
			noHideLoading: false,
			loadData: true,
		}
	},
	computed: {
		loadingStatus() {
			if (this.end) {
				return 'nomore'
			} else if (this.loading) {
				return 'loading'
			} else {
				return 'loadmore'
			}
		}
	},
	onReachBottom() {
		if (this.end||!this.loadData) return
		this.current++
		this.getData(false)
	},
	methods: {
		getData(refresh = false) {
			console.log("售后订单")
			console.log(this.params)
			return new Promise(resolve => {
				this.isSearching = true
				if (refresh) {
					this.current = 1
					this.total = 1
					this.end = false
					this.$utils.loading()
				} else {
					this.loading = true
				}
				if (this.listUrl) {
					api[this.httpMethod](this.listUrl, {
						...this.managerId?{userId:this.managerId}:{},
						...this.showType?{userType:this.showType}:{},
						current: this.current,
						size: this.size,
						...this.params ? this.params : {}
					},{
						noHideLoading: this.noHideLoading
					}).then(res => {
						this.dataList = refresh ? (res.data.records || []) : [...this.dataList, ...(res
							.data
							.records || [])];
						if (res.data.pages <= this.current) {
							this.end = true
						}
						this.getDataNext&&this.getDataNext()
					}).finally(() => {
						this.loading = false
						this.initLoading = false
						resolve()
					})
				}
			})
		},
		deleteData(id, index) {
			this.$utils.loading()
			api.delete(this.deleteUrl + '/' + id).then(res => {
				this.$utils.showToast('删除成功')
				this.dataList.splice(index, 1)
			})
		},
		updateData(delta) {
			this.$utils.loading()
			api.put(this.updateUrl, {
				...this.params,
			}).then(res => {
				if (!delta) {
					this.getData(true)
				} else {
					this.$utils.navigateBack(delta)
				}
			})
		}
	}
}